Metaprogramming
(How to make Pluto)
The package Pluto.jl could not load because it failed to initialize.
That's not nice! Things you could try:
- Restart the notebook.
- Try a different Julia version.
- Contact the developers of Pluto.jl about this error.
You might find useful information in the package installation log:
What is code?
Julia code comes in many forms. On its way from your thoughts to raw CPU instructions, the code undergoes a number of transformations. Every time that we go down a layer, we get to a structure that is more powerful and explicit, but less expressive.
Thoughts in your head
A text file with code (
String
)A syntax tree (
Expr
)
...
CPU instructions
Syntax parsing
When you write Julia code, you do so by writing a text file. Try writing some Julia code in the box below!
UndefVarError: TextField not defined
Here is what happened, the most recent locations are first:
- macro expansionfrom This cell: line 125
- Show more...
Here is your code, in its original form, a String
:
Another cell defining test_code contains errors.
Another cell defining test_code contains errors.
This is where we begin our story. The first thing that Julia does is syntax parsing: it goes from a String
to an Expr
.
Another cell defining test_code contains errors.
Another cell defining test_code contains errors.
That's right! Julia code is just another object in Julia! But what we see might be a little confusing: it is just the code that we typed, right?
Well, not exactly. What you see is Julia's built-in rich display, which does its best to make the Expr
readable for us. The most readable way to display an abstract Expr
is to show the equivalent code.
So instead, let's look directly at the internal structure of test_expr
:
Another cell defining test_code contains errors.
Evaluation
UndefVarError: TextField not defined
Here is what happened, the most recent locations are first:
- macro expansionfrom This cell: line 125
- Show more...
Another cell defining eval_code contains errors.
Another cell defining eval_code contains errors.
sprint_dump (generic function with 1 method)
parse_clean (generic function with 1 method)